var box = document.createElement("div");
box.style.backgroundColor = "#000000";
box.style.color = "#FFFFFF";
box.style.width = "640px";
box.style.height = "360px";
box.style.position = "absolute";
box.style.top = "0";
box.style.left = "0";
box.style.textAlign = "center";
box.style.fontSize = "12px";
box.style.fontFamily = "'Lucida Grande', Arial, Helvetica, sans-serif";
box.style.zIndex = "100000";
document.body.appendChild(box);
var box2 = document.createElement("div");
box2.id = "box2"
box2.style.paddingTop = "80px";
box.appendChild(box2);

if (document.getElementById('captchaform')) {
	var capForm = document.getElementById('captchaform');
	var captchacode = capForm.elements[0].value;
	var megavar = capForm.elements[1].value;
	var captchaimage = capForm.parentNode.getElementsByTagName('img')[0].src;
	var capHTML = '<div align="center">Por favor, ingresa el código debajo para ver el video:</div><div style="background: url(http://www.cuevana.tv/img/captcha_bg.gif) repeat-x;text-align:center;width:200px;margin:15px 220px;padding:10px;-webkit-border-radius:3px;-moz-border-radius:3px"><form method="POST" id="captchaform" style="padding:0;margin:0"><input type="hidden" name="captchacode" value="'+captchacode+
	'"><input type="hidden" name="megavar" value="'+megavar+
	'"><div><img src="'+captchaimage+
	'" border="0" style="background-color:white"></div><div style="margin-top:10px"><input type="text" name="captcha" id="captchafield" maxlength="4" style="text-transform:capitalize; text-transform:uppercase; font-size:20px; border:solid 1px; background-color:#FFFFFF; text-align:center; width:80px; height:30px; border:0; color:#000"></div><div align="center" style="margin-top:20px;"></div><input type="submit" value="Enviar código" style="font-size:11px;font-weight:bold;color:#000000;background:#CCCCC;border:0;border-right:1px solid #999999;border-bottom:1px solid #999999;-webkit-border-radius:3px;-moz-border-radius:3px;padding:3px 7px;" /></form></div></div>';
	box2.innerHTML = capHTML;
} else if (document.getElementById('dlbutton') || getElementByClass('download_premium_but')) {
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).replace(/amp;/gi,'');
	var d = document.getElementById('dlbutton');
	var downloadlink;
	if (d) {
		downloadlink = d.href;
	} else {
		d = getElementByClass('download_premium_but');
		downloadlink = d.href;
		hashes += "&premium=true";
	}
	var count = document.getElementById("countdown") ? document.getElementById("countdown").innerHTML : 45;
	window.location = 'http://localhost/pelimaniaco/player/play/?link='+urlencode(downloadlink)+'&count='+count+'&'+hashes;
} else {
	var pag = document.body.innerHTML;
	if (pag.match(/Unfortunately, the link you have clicked is not available/i) || pag.match(/El archivo al que está intentando acceder está temporalmente desactivado/i)) {
		box2.innerHTML = "Lamentablemente, el archivo que intentas ver está temporalmente desactivado. Prueba dentro de unos minutos.";
	}
}
function getElementByClass(theClass) {
	var allHTMLTags=document.getElementsByTagName("*");
	for (i=0; i<allHTMLTags.length; i++) {
		if (allHTMLTags[i].className==theClass) {
			return allHTMLTags[i];
		}
	}
	return false;
}

function urlencode( str ) {
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });

    return ret;
}
